/**
 * bug
 * safari: splitter bar is colorless
 */
if (inweo.get("inweo.widgets.splitter") != true) {
	inweo.set("inweo.widgets.splitter", true);
	inweo.set("inweo.widgets.hsplitter", true);
	inweo.set("inweo.widgets.vsplitter", true);
	inweo.widgets.splitter = inweo.core.widget.extend({
		initialize: function() {
			return new inweo.widgets.hsplitter();
		}
	});
	inweo.widgets.hsplitter = inweo.core.widget.extend({
		initialize: function() {
			var self = this;
			this.orient = "horizontal";
			this.widget = new Element("div");
			this.widget.addClass("splitter");
			this.widget.addClass("hSplitter");
			this.registerWidget("splitter");
			
			this.left = new Element("div");
			this.left.addClass("hSplitterLeft");
			this.left.injectInside(this.widget);

			this.bar = new Element("div");
			this.bar.addClass("hSplitterBar");
			this.bar.injectInside(this.widget);

			this.right = new Element("div");
			this.right.addClass("hSplitterRight");
			this.right.injectInside(this.widget);

			this.br = new Element("div");
			this.br.setStyle("clear", "both");
			this.br.injectInside(this.widget);

			var leftWidth = null;
			var minRightWidth = null;
			var barOffsetLeft = null;
			this.resizer = new Drag(this.left, {
				handle: self.bar,
				modifiers: {
					"x": "width",
					"y": null
				},
				onStart: function() {
					var hSplitterWidth = self.widget.offsetWidth;
					var rightMinWidth = self.right.getStyle("min-width").toInt();
					var barWidth = self.bar.getStyle("width").toInt();
																								// 8?
					self.left.setStyle("max-width", (hSplitterWidth - (rightMinWidth + barWidth)) - 8 + "px");
				}
			});
			window.addEvent("resize", function() {});
		},
		pack: function(child, side) {
			if (side == "left") {
				child.__pack(this.left);
			} else if (side == "right") {
				child.__pack(this.right);
			}
		}
	});
	inweo.widgets.vsplitter = inweo.core.widget.extend({
		initialize: function() {
			var self = this;
			this.orient = "vorizontal";
			this.widget = new Element("div");
			this.widget.addClass("splitter");
			this.widget.addClass("vSplitter");
			this.registerWidget("splitter");
			
			this.top = new Element("div");
			this.top.addClass("vSplitterTop");
			this.top.injectInside(this.widget);

			this.bar = new Element("div");
			this.bar.addClass("vSplitterBar");
			this.bar.injectInside(this.widget);

			this.bottom = new Element("div");
			this.bottom.addClass("vSplitterBottom");
			this.bottom.injectInside(this.widget);

			this.resizer = new Drag(this.top, {
				handle: self.bar,
				modifiers: {
					"x": null,
					"y": "height"
				},
				onStart: function() {
					var vSplitterHeight = self.widget.offsetHeight;
					var bottomMinHeight = self.bottom.getStyle("min-height").toInt();
					var barHeight = self.bar.getStyle("height").toInt();
					self.top.setStyle("max-height", (vSplitterHeight - (bottomMinHeight + barHeight)) + "px");
				}
			});
			window.addEvent("resize", function() {});
		},
		pack: function(child, side) {
			if (side == "top") {
				child.__pack(this.top);
			} else if (side == "bottom") {
				child.__pack(this.bottom);
			}
		}
	});
}